package com.shujia.flink

import org.apache.flink.api.scala.{ExecutionEnvironment, _}

object BatchWordCOunt {


  def main(args: Array[String]): Unit = {

    //创建flink上下文对象
    val env = ExecutionEnvironment.getExecutionEnvironment


    //读取文件   创建DataSet
    val lines = env.readTextFile("data/words.txt")

    val words = lines.flatMap(_.split(","))

    val tople = words.map((_, 1))


    //统计单词数量
    val count = tople
      //reduceBykey
      .groupBy(_._1)
      .reduce((x, y) => (x._1, x._2 + y._2))


    //打印结果
    count.print()

  }
}
